//
//  ViewController.m
//  10805-图片-PickerView 图片
//
//  Created by student on 16/2/27.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIPickerViewDelegate,UIPickerViewDataSource>
@property (strong, nonatomic) IBOutlet UIPickerView *pickerView;
@property (strong, nonatomic) NSArray *nameArr;

@property (strong, nonatomic) NSArray *voiceArr;

@property (strong, nonatomic) NSArray *imageArr;

@property (weak, nonatomic) IBOutlet UILabel *label;
@property (weak, nonatomic) IBOutlet UILabel *label1;
@end

@implementation ViewController


//  @[@"老鼠",@"鹅",@"猫",@"狗",@"蛇",@"狗熊",@"猪"]
//  @[@"呼噜呼噜",@"吼吼",@"嘶嘶",@"汪汪",@"喵喵",@"哦哦",@"吱吱"]
//  @[[UIImage imageNamed:@"mouse.png"],
//[UIImage imageNamed:@"goose.png"],
//[UIImage imageNamed:@"cat.png"],
//[UIImage imageNamed:@"dog.png"],
//[UIImage imageNamed:@"snake.png"],
//[UIImage imageNamed:@"bear.png"],
//[UIImage imageNamed:@"pig.png"]
//];
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.pickerView.delegate = self;
    self.pickerView.dataSource = self;
    self.nameArr = @[@"老鼠",@"鹅",@"猫",@"狗",@"蛇",@"狗熊",@"猪"];
    self.voiceArr = @[@"呼噜呼噜",@"吼吼",@"嘶嘶",@"汪汪",@"喵喵",@"哦哦",@"吱吱"];
    self.imageArr = @[[UIImage imageNamed:@"mouse.png"],
                      [UIImage imageNamed:@"goose.png"],
                      [UIImage imageNamed:@"cat.png"],
                      [UIImage imageNamed:@"dog.png"],
                      [UIImage imageNamed:@"snake.png"],
                      [UIImage imageNamed:@"bear.png"],
                      [UIImage imageNamed:@"pig.png"]
                      ];

}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
    return 2;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
    if (component == 0) {
        return self.imageArr.count;
    }
    else{
        return self.voiceArr.count;
    }
}

-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    if (component == 0) {
        UIImageView *imageView = [[UIImageView alloc] initWithImage:self.imageArr[row]];
        return imageView;
    }
    else{
        UILabel *label = [[UILabel alloc] init];
        [label setText:self.voiceArr[row]];
        [label setTextAlignment:NSTextAlignmentCenter];
        return label;
    }
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{
    if (component == 0){
        return 100;
    }
    else{
        return 100;
    }
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
    if (component == 0){
        return 100;
    }
    else{
        return 100;
    }
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    if (component == 0) {
        [self.label setText:[NSString stringWithFormat:@"你选择的动物名称叫做%@",self.nameArr[row]]];
    }
    else {
        [self.label setText:[NSString stringWithFormat:@"你选择的动物叫声%@",self.voiceArr[row]]];
    }
    NSInteger curCom1 = [self.pickerView selectedRowInComponent:0];
    NSInteger curCom2 = [self.pickerView selectedRowInComponent:1];
    if ((curCom1 + curCom2) == self.nameArr.count - 1) {
        [self.label1 setText:@"匹配"];
    }
    else{
         [self.label1 setText:@"不匹配"];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    
}

@end
